$("document").ready(function() {
	
	$("#demand_submit").click(function(){
		$("#reset").hide();
		$("#update_send_to_admin").hide();
		$(this).hide();
		alert('需求表輸入成功');
		$("form").submit();
		
	});
	
	
	$("#demand_update").click(function(){
		//$("")
		$("#update_send_to_admin").hide();
		$(this).hide();
		alert('需求表更新成功');
		$("form").submit();
		
	});
	
	
	
/*$("#demand_do_excel").click(function() {

		var values = $('input:checkbox:checked').map(function() {
			return this.value;
		}).get();

		$("form#userinfo").attr("action", "/demand/excel");
		$("form#userinfo").submit();
	});

	$("#demand_do_excel_for_selected").click(function() {

		var values = $('input:checkbox:checked').map(function() {
			return this.value;
		}).get();

		$("form#userinfo").attr("action", "/demand/excel");
		$("form#userinfo").submit();

	});

	//demand_do_excel_for_selected
	$(":checkbox").each(function() {
		$(this).click(function() {

			if ($(this).attr('checked')) {

				$.post("/demand/save_demand_id", {
					id : $(this).val(),
					"is_del" : 0
				}, function(result) {
					//alert(result);
				});

			} else {

				$.post("/demand/save_demand_id", {
					id : $(this).val(),
					"is_del" : 1
				}, function(result) {
					//alert(result);
				});
			}

		});
	});
	
	*/

//傳出給小劉陳傳

$("#update_send_to_admin").click(function(){

	//alert('傳出給小劉陳傳');
	$("#broker").val(1);
	$("#front_man").val(1);
	$("form").submit();
});

	


	
});



function selectCheckBox() {
	if ($("#select_demand").attr("checked")) {
		$("[id='demand_check_box']").attr("checked", 'true');
	} else {
		$("[id='demand_check_box']").removeAttr("checked");
	}
}

function open_window(obj) {
	var chk = $(obj).attr('checked');
	if (chk)
		window.open('/consignment_select', '_blank');
}

function show_surroundings() {

	if ($("#surroundings").css("display") == "none") {

		$("#surroundings").show();

		$("#surroundings_icon").removeClass("icon-plus");
		$("#surroundings_icon").addClass("icon-minus");

	} else {


		$("#surroundings").hide();
		$("#surroundings_icon").removeClass("icon-minus");
		$("#surroundings_icon").addClass("icon-plus");

	}

}

function query_more() {
	if ($("#query_more").css("display") == "none") {
		$("#query_more").show();
		$("#query_more_icon").removeClass("icon-plus");
		$("#query_more_icon").addClass("icon-minus");
	} else {
		$("#query_more").hide();
		$("#query_more_icon").removeClass("icon-minus");
		$("#query_more_icon").addClass("icon-plus");
	}
}

function get_line(id) {
	
	$.post("/mrt/get_mrt_ajax/", {
		mrt_line_id : $("#mrt_line" + id).val()
	}, function(result) {
		if (result) {
			$("#mrt_start" + id).html(result);
			$("#mrt_until" + id).html(result);
		} else {
			alert("出錯");
		}
	});
	
}

function demand_match_form() {
	//change by hua-li victor
	//alert("victor");
	$("form").attr("action", "/object/data_query_results_match");
	//alert("= =");
	//alert( $("form#object_f").attr("action"));
	$("form").submit();
}

function checkform() {
	//change by hua-li victor
	//alert("victor");
	$("form").attr("action", "/demand/data_entry_submit");

	//alert("= =");
	//alert( $("form#object_f").attr("action"));

	$("form").submit();

	/*

	 if($("#name").val()==""){

	 alert("請填寫客戶姓名");
	 setTimeout(function() {
	 $("#name").focus();
	 }, 0);
	 return false;

	 }else {

	 return true;

	 }

	 */
}




function selected_sell() {
	if ($("#type_sell").attr("checked")) {
		$("#selected_sell").show();
	} else {
		$("#selected_sell").hide();
	}
}

function selected_rent() {
	if ($("#type_rent").attr("checked")) {
		$("#selected_rent").show();
		$("#selected_sell").show();
		
	} else {
		$("#selected_rent").hide();
		$("#selected_sell").hide();
	}
}

function show_emphasis_area(id) {
	$("input[type=radio][name=emphasis_area_value][value=0]").attr("checked", "checked");
	$('#emphasis_area_select').dialog({
		autoOpen : true,
		modal : true,
		width : 620,
		buttons : {
			"確定" : function() {
				$('#' + id).val($("input[name='emphasis_area_value']:checked").val());
				$(this).dialog("close");
			},
			"取消" : function() {
				$(this).dialog("close");
			}
		}
	});

}

function show_administrative_area(id) {
	$('#administrative_area_select').dialog({
		autoOpen : true,
		modal : true,
		width : 300,
		buttons : {
			"確定" : function() {
				if ($('#administrative_area').val() != "")
					$('#' + id).val($('#administrative_area').val());
				$(this).dialog("close");
			},
			"取消" : function() {
				$(this).dialog("close");
			}
		}
	});

}

function administrative_area_choose() {
	$('#administrative_area').val($('#administrative_country').find("option:selected").text());

}

function administrative_area_city_choose() {
	$.post("/address/county", {
		id : $("#administrative_city").val()
	}, function(result) {
		if (result != "") {
			$("#administrative_country").html(result);
		}
	});
}

function show_building_name(id) {
	$("input[type=radio][name=building_name_value][value=0]").attr("checked", "checked");
	$('#building_name_select').dialog({
		autoOpen : true,
		modal : true,
		width : 620,
		buttons : {
			"確定" : function() {
				$('#' + id).val($("input[name='building_name_value']:checked").val());
				$(this).dialog("close");
			},
			"取消" : function() {
				$(this).dialog("close");
			}
		}
	});

}

/*
function show_object_case_name(id) {
	$("input[type=radio][name=object_case_name_value][value=0]").attr("checked", "checked");
	$('#object_case_name_select').dialog({
		autoOpen : true,
		modal : true,
		width : 620,
		buttons : {
			"確定" : function() {
				$('#' + id).val($("input[name='object_case_name_value']:checked").val());
				$(this).dialog("close");
			},
			"取消" : function() {
				$(this).dialog("close");
			}
		}
	});

}
*/

function show_object_case_name(id) {
	
	$("input[type=radio][name=object_case_name_value][value=0]").attr("checked", "checked");
	$('#object_case_name_select').dialog({
		autoOpen : true,
		modal : true,
		width : 620,
		buttons : {
			"確定" : function() {
				$('#' + id).val($("input[name='object_case_name_value']:checked").val());
				$(this).dialog("close");
			},
			"取消" : function() {
				$(this).dialog("close");
			}
		}
	});

}

function circle_city_choose() {

	$.post("/address/county", {
		id : $("#circle_city").val()
	}, function(result) {
		if (result != "") {
			$("#circle_country").html(result);
		}
	});
}

function circle_country_choose() {

//alert('area :'+ $('#circle_country').find("option:selected").val());
	$.post("/circle/circle_josn", {
		city : $('#circle_city').find("option:selected").text(),
		area : $('#circle_country').find("option:selected").text()
	}, function(result) {
		if (result != "") {
			$("#circle").html(result);
		}
	});
}

function circle_choose() {
	$('#circle_value').val($('#circle').find("option:selected").text());
}

function show_circle(id) {
	$('#circle_value').val($('#' + id).val());
	$('#circle_select').dialog({
		autoOpen : true,
		modal : true,
		width : 480,
		buttons : {
			"確定" : function() {
				if ($('#circle_value').val() != "")
					$('#' + id).val($('#circle_value').val());
				$(this).dialog("close");
			},
			"取消" : function() {
				$(this).dialog("close");
			}
		}
	});
}

function initializemap() {
	var mapOptions = {
		zoom : 8,
		center : new google.maps.LatLng(24.997344353729364, 121.55073852549200),
		mapTypeId : google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}

function loadScript() {

}

function show_map() {
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' + 'callback=initializemap';
	document.body.appendChild(script);

}

function show_floors(id) {
	$('#floors_select').dialog({
		autoOpen : true,
		modal : true,
		width : 320,
		buttons : {
			"確定" : function() {
				$('#' + id).val($('#floors_value').val());
				$(this).dialog("close");
			},
			"取消" : function() {
				$(this).dialog("close");
			}
		}
	});
}

function floors_choose(i) {
	if ($('#floors_value').val() == "")
		$('#floors_value').val(i);
	else
		$('#floors_value').val($('#floors_value').val() + "," + i);
}
